package io.p2p.stream.stun.util;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.ByteBuffer;

public class BuildPacketsUtil {

    public static final int SEQ_SIZE = 8;

    public static ByteBuf wrap(long seqNum, String msg){
        byte[] msgBytes = msg.getBytes();
        byte[] buf = new byte[msgBytes.length + SEQ_SIZE];
        byte[] seqBytes = ByteBuffer.allocate(SEQ_SIZE).putLong(seqNum).array();
        System.arraycopy(seqBytes,0,buf,0,SEQ_SIZE);
        System.arraycopy(msgBytes,0,buf,seqBytes.length,msgBytes.length);
        ByteBuf byteBuf = Unpooled.copiedBuffer(buf);
        return byteBuf;
    }
}
